package com.fudan.biz.visualize.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fudan.biz.visualize.entity.DashboardDef;
import com.fudan.biz.visualize.service.DashboardDefService;
import com.fudan.framework.base.DaoService;
import com.fudan.framework.entity.ResponseMsg;
import com.fudan.framework.entity.TableJson;
import com.fudan.framework.utils.EntityUtils;
import com.fudan.framework.web.controller.DeleteController;

@RestController
@RequestMapping("biz/dashboard/def")
public class DashboardDefController implements DeleteController<DashboardDef>{

	@Autowired
	private DashboardDefService dashboardDefService;

	@RequestMapping("/save")
	public ResponseMsg save(HttpServletRequest request) {
		try {
			DashboardDef dashboardDef = EntityUtils.toEntity(request, DashboardDef.class);
			dashboardDefService.add(dashboardDef);
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseMsg.build(500,e.getMessage());
		}
		return ResponseMsg.build(0);
	}

	@RequestMapping("/get")
	public ResponseMsg get(@RequestParam String id) {
		try {
			DashboardDef dashboardDef = dashboardDefService.get(id);
			return ResponseMsg.build(0,"success",dashboardDef);
		}catch(Exception e) {
			return ResponseMsg.build(500,e.getMessage());
		}
	}
	@RequestMapping("/list")
	public TableJson list(HttpServletRequest request) {
		List<DashboardDef> pages = dashboardDefService.pages(request);
		return TableJson.build(pages, dashboardDefService.countAll());
	}

	@Override
	public DaoService<DashboardDef> injectService() {
		return dashboardDefService;
	}
}
